package flexo.input.entity;

import flexo.input.Event;
import flexo.input.EventListener;

/**
 * Entities that use the user input to move nodes.
 * Only one node will be modified by the entity.
 * If you try to attach it to more nodes, the entity will
 * automatically deattach from the other nodes by itself.
 * 
 * @author Miguel
 */
public abstract class Entity extends flexo.scene.ExclusiveEntity implements EventListener
{	
	protected flexo.input.InputSystem is = (flexo.input.InputSystem)flexo.Kernel.getSystem(flexo.input.InputSystem.ID);
	protected float sensitivity;
	
	public Entity()
	{
		super(Type.INPUT);
		setSensitivity(1);
		is.addEventListener(this);
	}
	
	public void remove()
	{
		this.deattach();
		is.removeEventListener(this);
	}
	
	public void setSensitivity(float value)
	{
		if (value > 0)
		{
			this.sensitivity = value;
		}
	}
	
	@Override
	public void processEvent(Event e)
	{
		float step = is.getElapsedTime();
		step *= sensitivity * e.getValue();
		update(e, step);
	}
	
	protected abstract void update(Event e, float value);
}
